<template>
    <div id="box">
      
        <el-container class="home-containter">
            <!--头部区域-->
  <el-header>  
    <div>
        <img src="../assets/heima.png" alt="">
        <span>商城后台管理系统</span>
    </div>
    <el-button type="info" @click="emit()">退出</el-button>
</el-header>
  <el-container>
<!--侧边栏-->
    <el-aside :width="isCollapse ? '64px' : '200px'">
        <!--折叠-->
        <div class="toggle-button" @click="toggleCollspace()">|||</div>
        <el-menu
      background-color="#333744"
      text-color="#fff"
      active-text-color="#409eff" :unique-opened="true" :collapse="isCollapse" :collapse-transition	="false" :router="true" :default-active="$route.path">
      <!--一级菜单-->
                   <!--只接受字符串-->
      <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
        <template slot="title">
          <i :class="iconsObj[item.id]"></i>
          <span>{{  item.authName  }}</span>
        </template>
           <!--二级菜单-->
          <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
            <template slot="title">
          <i class="el-icon-menu"></i>
          <span>{{subItem.authName}}</span>
        </template>
          </el-menu-item>
     
      </el-submenu>
     
    </el-menu>
    </el-aside>
    <!--右边-->
    <el-main>
   <router-view></router-view>
    </el-main>
  </el-container>
</el-container>
    </div>
</template>

<script>
export default {
    data() {
        return {
            //左侧分类列表
            menulist: [],
            //解决一级图标问题
            iconsObj: {
                '125': 'iconfont icon-users',
                '103': 'iconfont icon-tijikongjian',
                '101': 'iconfont icon-shangpin',
                '102': 'iconfont icon-danju',
                '145': 'iconfont icon-baobiao'
            },
            //是否收起左侧边栏
            isCollapse: false

        }
    },
    created() {
        this.getMenulist()
    },
    methods: {
        //点击退出，退出登录
        emit() {
            window.sessionStorage.clear()
            this.$router.replace("/login")
        },
        //获取左侧列表
        async getMenulist() {
            let { data } = await this.$http.get('menus')
            // console.log(data)
            if (data.meta.status !== 200) return this.$message.error("左侧列表数据请求失败")
            this.menulist = data.data
        },
        //点击显示与隐藏左侧边栏
        toggleCollspace(){
     this.isCollapse=!this.isCollapse
        }
    }
}
</script>

<style lang="less" scoped>
.home-containter {
    height: 100%;
}

.el-header {
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 20px;

    >div {
        display: flex;
        align-items: center;

        span {
            margin-left: 15px;
        }
    }
}

.el-aside {
    background-color: #333744;
}

.el-main {
    background-color: #eaedf1
}
.iconfont{
    margin-right: 10px;
}
.toggle-button{
    background-color: #4a5064;
    color: #fff;
    font-size: 10px;
    text-align: center;
    line-height: 24px;
    letter-spacing: 0.2em;
    cursor: pointer;
}
</style>